<?php
include_once("survey_answer_dao_base.php");

class survey_answer_dao extends survey_answer_dao_base
{
	function get_survey_answer_list_by_survey_question_id($survey_question_id)
	{
		try
		{
			$dbh = new PDO(Constants::$connectionString, Constants::$username, Constants::$password);
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			$dbh->beginTransaction();

			$aos = array();
			$stmt = $dbh->query("SELECT * FROM survey_answer sa WHERE sa.survey_question_id = ".$survey_question_id);
			$rows = $stmt->fetchAll();
			foreach($rows as $row)
			{
				$s = new survey_answer($row["survey_answer_id"],$row["survey_question_id"],$row["survey_answer_content"],$row["survey_answer_mark"]);
				$aos[] = $s;
			}

			$dbh->commit();
			$dbh = null;
			
			return $aos;
		}
		catch(PDOException $e)
		{
			echo '<br />' . $e->getMessage();
			$dbh->rollback();
		}	
	}
	
	
	function delete_survey_answer_by_survey_question_id($survey_question_id)
	{
		try
		{
			$dbh = new PDO(Constants::$connectionString, Constants::$username, Constants::$password);
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			$dbh->beginTransaction();

			$stmt = $dbh->prepare("DELETE FROM survey_answer WHERE survey_question_id = :survey_question_id");
			$stmt->bindParam(':survey_question_id', $survey_question_id, PDO::PARAM_INT);
			$stmt->execute();
			
			$dbh->commit();
			$dbh = null;
		}
		catch(PDOException $e)
		{
			echo '<br />' . $e->getMessage();
			$dbh->rollback();
		}	
	}
}
?>